﻿using System;
using System.Diagnostics.Contracts;

namespace O1.Data.Traversal
{
    [ContractVerification(true)]
    public class EdgeFilter : Filter
    {
        private readonly EdgeSet inclusions;

        private readonly EdgeSet exclusions;

        public EdgeFilter() : this(null, null)
        {
        }

        public EdgeFilter(EdgeSet inclusions) : this(inclusions, null)
        {
        }

        public EdgeFilter(EdgeSet inclusions, EdgeSet exclusions)
        {
            this.inclusions = inclusions;
            this.exclusions = exclusions;
        }

        public override ObservationInterests StartEdge(Edge edge, EdgeDirections direction)
        {
            var edgeType = edge.EdgeType;
            if (this.exclusions != null)
            {
                if (this.exclusions.Contains(direction, edgeType))
                {
                    return ObservationInterests.None;
                }
            }

            if (this.inclusions == null)
            {
                return ObservationInterests.Interested;
            }

            return this.inclusions.Contains(direction, edgeType) ? ObservationInterests.Interested : ObservationInterests.None;
        }
    }
}
